# 元组：多个元素组成一组
# 元组是不可变类型的，元素是不能修改的

# 创建元组
tuple_val = (1,'hello',[1,2,3,4],('a','b','c','d'))
empty_tuple = tuple()
# 只有一个元素这样定义 输出是int类型 需要定义成 (1,)
tuple_1 = (1)
print(type(tuple_1)) # 输出 <class 'int'>
tuple_2 = (1,)
print(type(tuple_2)) # 输出 <class 'tuple'>

# 索引和切片
print(tuple_val[2])
print(tuple_val[1:3])
print(tuple_val[-1][1:3])

# 遍历
for i in tuple_val:
    print(i)

# 不可变
# tuple_val[0] = 2 # 报错 'tuple' object does not support item assignment

# 常见操作
print(dir(tuple))

# 'count', 'index'
print(tuple_val.count(1))
print(tuple_val.index(1))


